<template>
  <div class="photoInfo_box">
    <!-- 标题 -->
    <h2>{{infoList.title}}</h2>
    <!-- 时间信息 -->
    <div class="time_tag">
      <span>时间: {{infoList.add_time | timeFormat}}</span>
      <span>点击: {{infoList.click}}</span>
    </div>
    <!-- 图片 -->
    <img class="preview-img" 
    v-for="(item, index) in imgList" :key="index"
    :src="item.src" height="100" 
    @click="$preview.open(index, imgList)">
    <!-- 内容 -->
    <div v-html="infoList.content" class="content"></div>
    <!-- 评论 -->
    <comment :id="id"></comment>
  </div>  
</template>

<script>
import { Toast } from "mint-ui";

// 评论组件
import comment from "../myModules/comment.vue";
export default {
  components: {
    comment
  },
  data() {
    return {
      infoList: {},
      imgList: [],
      id: this.$route.params.id
    };
  },
  created() {
    this.getInfo();
    this.getImg();
  },
  methods: {
    getInfo() {
      this.$http.get("api/getimageInfo/" + this.id).then(res => {
        if (res.body.status === 0) {
          this.infoList = res.body.message[0];
        }
      });
    },
    getImg() {
      // 使用缩略图
      this.$http.get("api/getthumimages/" + this.id).then(res => {
        if (res.body.status === 0) {
          // 遍历图片列表设置默认样式(缩略图)
          res.body.message.forEach(item => {
            item.w = 600;
            item.h = 400;
          });
          this.imgList = res.body.message;
        }
      });
    }
  }
};
</script>

<style  lang='less'>
.photoInfo_box {
  padding: 0 5px;
  h2 {
    text-align: center;
    font-size: 18px;
  }
  .time_tag {
    font-size: 14px;
    color: #26a2ff;
    display: flex;
    justify-content: space-between;
  }
  .preview-img {
    margin: 4px;
  }
  .content {
    font-size: 14px;
    text-indent: 2em;
  }
}
</style>